import Vue from 'vue'
import './cube-ui'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'
import Cube from 'cube-ui' //引入cube组件库
import VueAwesomeSwiper from 'vue-awesome-swiper'//引入swiper组件库
import 'swiper/swiper-bundle.css'
import axios from 'axios'

Vue.use(Cube)//使用cube组件库
Vue.use(VueAwesomeSwiper)//使用swiper组件库
Vue.config.productionTip = false
Vue.prototype.$http=axios;

//路由守卫的前置钩子，登录验证
router.beforeEach((to,from,next)=>{
  //先判断是否登录
  if(window.localStorage.getItem('token')){//已经登录
    if(to.path === '/login'){//输入login
      window.localStorage.removeItem('token');//清除token
      window.localStorage.removeItem('id');//清除id
      next({path: '/login'})
    }else{
      if(to.matched.length){//页面存在
        next();
      }else{//页面不存在
        next({path: '/notFind'});
      }
    }
  }else{//一次都没有登录
    if(to.path === '/login'){//输入的是/login
        next();
    }else{//跳转至/login
      next({path: '/login'});
    }
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
